//
//  SDLoginViewController.swift
//  Seed
//
//  Created by Samuel on 2017/6/5.
//  Copyright © 2017年 RedSoft. All rights reserved.
//

import UIKit
import SVProgressHUD

class SDLoginViewController: YMBaseViewController {

    @IBOutlet weak var phoneField: UITextField!
    
    @IBOutlet weak var pwdField: UITextField!
    
    @IBOutlet weak var loginBtn: UIButton!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        configUI()
    }
    
    func configUI(){
        navigationItem.title = "手机号登陆"
        
        loginBtn.clipsToBounds = true
        loginBtn.layer.cornerRadius = 5.0
        
        phoneField.text = "18661637641"
        pwdField.text = "111111"
    }

    @IBAction func login(_ sender: UIButton) {
        if !(phoneField.text! =~ RegexHelper.isIphoneNum) {
            SVProgressHUD.showError(withStatus: "请输入正确的手机号")
            return
        }
        if (pwdField.text?.isEmpty)! {
            SVProgressHUD.showError(withStatus: "请输入密码")
            return
        }
        
        SVProgressHUD.show(withStatus: "正在登陆,请稍候...")
        SDNetworkTool.shared.login(withPhone: self.phoneField.text!, passwd: self.pwdField.text!) { (account:SDAccount) in
            printLog(account)
            SVProgressHUD.showSuccess(withStatus: "登陆成功")
            //保存当前账号信息
            SDAccountTool.shared.saveAccount(account)
            //保存登陆状态，跳转登陆
            appDelegate.setLoginStatus(true)
        }
    }

}
